<?
require("functions.php");

if (isset($_SESSION["groupe"])){
	$vysledek = mysql_query("select * from users where groupe='".$_SESSION["groupe"]."' and nick='".$_SESSION["nick"]."'");
	if (mysql_num_rows($vysledek) == 0) {
		mysql_query("insert into users (nick, groupe, password, lat, lon, time, color) values ('".$_SESSION["nick"]."', '".$_SESSION["groupe"]."', '".$_SESSION["heslo"]."', '".$_SESSION["lat"]."', '".$_SESSION["lon"]."', '".time()."', '".$_SESSION["color"]."')");
	}
	generate_kml();
} else {
	$vysledek = mysql_query("select * from users where groupe='".$_POST["groupe"]."'");
	if (mysql_num_rows($vysledek) == 0) {
		mysql_query("insert into users (nick, groupe, password, lat, lon, time) values ('".$_POST["nick"]."', '".$_POST["groupe"]."', '".$_POST["heslo"]."', '".$_POST["latitude"]."', '".$_POST["longitude"]."', '".time()."')");
		nastav_session();
	} else {
		$vysledek = mysql_query("select * from users where password='".$_POST["heslo"]."' and groupe='".$_POST["groupe"]."'");
		if (mysql_num_rows($vysledek) == 0) {
			echo '<?xml version="1.0" encoding="utf-8" ?>
				<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml" xmlns:locify="http://client.locify.com/locify_ns/1.0" xml:lang="cs" lang="cs">
				<head>
					<title>'.$lang["error"].'</title>
				</head>
				<body>
				  '.$lang["wrong_pass_1"].$_POST["groupe"].$lang["wrong_pass_2"].'
				</body>
				</html>';
		} else {
			$vysledek = mysql_query("select * from users where nick='".$_POST["nick"]."' and groupe='".$_POST["groupe"]."'");
			if (mysql_num_rows($vysledek) == 0) {
				mysql_query("insert into users (nick, groupe, password, lat, lon, time) values ('".$_POST["nick"]."', '".$_POST["groupe"]."', '".$_POST["heslo"]."', '".$_POST["latitude"]."', '".$_POST["longitude"]."', '".time()."')");
				nastav_session();
			} else {
				echo '<?xml version="1.0" encoding="utf-8" ?>
					<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
					<html xmlns="http://www.w3.org/1999/xhtml" xmlns:locify="http://client.locify.com/locify_ns/1.0" xml:lang="cs" lang="cs">
					<head>
						<title>'.$lang["error"].'</title>
					</head>
					<body>
					  '.$lang["wrong_pass_1"].$_POST["groupe"].$lang["wrong_pass_2"].'
					</body>
					</html>';
			}
		}
	}
}
	
?>
